package com.demo.common.domain.vo;

import com.demo.common.constants.Constants;
import com.demo.common.util.TracerUtil;

import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * BaseResult
 * 
 * @author demo
 * @date 2020-11-04 20:39:10
 */
@Getter
@NoArgsConstructor
public class BaseResult<T> {
    private String code = Constants.RESULT_SUCCEED_CODE;
    private String msg = Constants.RESULT_SUCCEED_MSG;
    private String traceId = TracerUtil.getTraceId();
    private T data;

    public BaseResult(T data) {
        this.data = data;
    }

    public BaseResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> BaseResult<T> success() {
        return new BaseResult<>(null);
    }

    public static <T> BaseResult<T> success(T data) {
        return new BaseResult<>(data);
    }

    public static <T> BaseResult<T> failure(String code, String msg) {
        return new BaseResult<>(code, msg);
    }

}
